#include <stdlib.h>
#include <string.h> // for memcpy
#include "testutils.hh"


namespace objectsaxparser {

  using std::string ;
  using std::vector ;

  string generateRandomString(int len, const string& source1, const string& source2 /* = "" */)
  {
  // first char
  if (len <= 0 )
      return "" ; // some defensive coding

    string::value_type c[len];
    const string& s2 = source2=="" ? source1 : source2 ;
    int i, idx ;
    int slen = s2.length() ;

    c[0] = source1.at(rand() % source1.length()) ;

        

    for( i = 1 ; i < len ; i++ ) {
      idx = rand() % slen ;
      c[i] = s2.at(idx) ;
    }


    return string(c, len) ;
  }

  string generateRandomString(int len, const vector<string>& strings, const string& source2 /* = "" */ )
  {
        // first char
      if (len <= 0 )
          return "" ; // some defensive coding

      string::value_type c[len];

      string s = strings[ rand() % strings.size() ] ;

      int l = (int)s.length() > len ? len : (int)s.length() ; // only as much as we have space for
      memcpy(c, s.c_str(), l) ;

      string s2 = generateRandomString(len - l, source2) ;
      
      if ( len - l > 0) 
          memcpy(c+l, s2.c_str(), len - l) ;

      return string(c, len) ;

  }

}
